home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12293 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  76 lines

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP with array declaration
  5. Date: 29 Mar 1996 21:56:13 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4jiidtINNpab@keats.ugrad.cs.ubc.ca>
  8. References: <315C7F92.30E18DFD@learning.c.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <315C7F92.30E18DFD@learning.c.com>, Ed  <ed@learning.c.com> wrote:
  12. >Hi,
  13. >
  14. >I don't know why the compiler (gcc) complains given this code:
  15. >
  16. >
  17. >...
  18. >...
  19. >#define STRING 81
  20. >
  21. >void sort_insert(char a[][STRING], unsigned int numdata) {
  22. >
  23. >...
  24. >...
  25. >
  26. >}
  27. >
  28. >
  29. >The compiler says that "two or more data types in declaration of
  30. >'sort_insert' "
  31.  
  32. It means that somewhere before the ``void sort_insert'' you have some other
  33. type keyword. You may have missed a semicolon or something silly like that:
  34.  
  35.  
  36. int
  37.  
  38. #define STRING 81
  39.  
  40. void sort_insert(void)
  41.  
  42. {
  43. }
  44.  
  45.  
  46. That will cause the same error. Why? Because there are two datatypes in the
  47. list of declaration specifiers for the function, namely ``int'' and ``void''.
  48.  
  49. You might not make such a stupid error, but you might make this:
  50.  
  51. struct foo {
  52.     int bar;
  53. }        /* NO SEMICOLON!! */
  54.  
  55. #define STRING 81
  56.  
  57. void sort_insert(...
  58.  
  59.  
  60. Now the compiler things you are trying to do this:
  61.  
  62.     struct foo { int bar; } void sort_insert(...)
  63.  
  64. a function that returns both void and a struct foo. Two types in a declaration
  65. specifier list, that is utterly illegal. That's like saying ``int char x;''.
  66. You gotta drop the struct, drop the void, or put in a semicolon between the
  67. struct declaration and the void.
  68.  
  69. >I'm new to 'C' and I don't see anything wrong with the above
  70. >declaration.
  71.  
  72. It's not in the declaration but stuff that precedes it. Check for missing
  73. semicolons. Also check inside any headers that you may have #included.
  74. -- 
  75.  
  76.